#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    bool increasingTriplet(vector<int>& nums) {
        if (nums.size() < 3) return false;

        vector<int> leftmin(nums.size());
        vector<int> rightmax(nums.size());

        leftmin[0] = nums[0];
        for (int i = 1; i < nums.size(); i++)
        {
            if (nums[i] < leftmin[i - 1])
            {
                leftmin[i] = nums[i];
            }
            else
            {
                leftmin[i] = leftmin[i - 1];
            }
        }

        rightmax[nums.size() - 1] = nums[nums.size() - 1];
        for (int i = nums.size() - 2; i > 0; i--)
        {
            if (nums[i] > rightmax[i + 1])
            {
                rightmax[i] = nums[i];
            }
            else
            {
                rightmax[i] = rightmax[i + 1];
            }
        }

        for (int i = 1; i < nums.size() - 1; i++)
        {
            if (nums[i] > leftmin[i] && rightmax[i] > nums[i])
                return true;
        }

        return false;
    }
};